package org.sidora.strata.context;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.windows.TopComponent;


/**
 * Action which shows ContextForm component
 * @author Enric Tartera, Juan Manuel Gimeno, Roger Masgoret
 * @version 1.0
 */
public class ContextFormAction extends AbstractAction {
    
    public ContextFormAction() {
        super(NbBundle.getMessage(ContextFormAction.class, "CTL_ContextFormAction"));
        putValue(SMALL_ICON, new ImageIcon(Utilities.loadImage(ContextFormTopComponent.ICON_PATH, true)));
    }
    
    public void actionPerformed(ActionEvent evt) {
        TopComponent win = ContextFormTopComponent.findInstance();
        win.open();
        win.requestActive();
    }
    
    public void actionPerformedShow(){
        ContextFormTopComponent win = ContextFormTopComponent.findInstance();
        win.open();
        win.requestActive();
        win.fillContextItems();
    }
    
    public TopComponent getTopComponent(){
        return ContextFormTopComponent.findInstance();
    }
    
    public void emptyFields(){
        ContextFormTopComponent win = ContextFormTopComponent.findInstance();
        win.emptyContextItems();
    }

    public void saveFields(){
        ContextFormTopComponent win = ContextFormTopComponent.findInstance();
        win.saveContextFields();
    }
    
    public void cerrar(){
        ContextFormTopComponent win = ContextFormTopComponent.findInstance();
        win.close();
    }
}
